/*
avi.h
*/
#ifndef AVI_H__
#define AVI_H__
#include <stdio.h>
#include <string.h>

#include <sys/types.h>

#include <windows.h>
#include <fcntl.h>
#include <stdlib.h>

#include "llist.h"

#ifdef __cplusplus
extern "C" {
#endif

//prevent avi file from becoming too big
#define MAX_FRAME_SUM 30000
/* 2 GB - 100MB limit */
#define MAX_RIFF_SZ  2147483648 
#define FPS		4		// default avi fps
#define WIDTH	800		// default avi width
#define HEIGHT	600		// default avi height

#define off64_t __int64

typedef struct _Jpeg_Data Jpeg_Data;

struct _Jpeg_Data
{
  unsigned int size;
  unsigned int offset;
//  char name[0]; /* i.e. variable length structure */
};

#define JPEG_DATA_SZ (sizeof(DWORD) * 2)

///////////////////////////////////////////////////////

//2005-11-09
//avi global data stuct during AVI Recording

typedef struct _Avi_Data Avi_Data;

struct _Avi_Data
{
  off64_t jpg_sz_64 ;
  unsigned int frame_sum;
  List *frlst;
  List *frlst_back;
};

/*avi functions*/

FILE * avi_open(const char *filename,const char *mode);
//int avi_write(FILE * avifile, char * jpg_buff,unsigned int jpg_length);
//void avi_create(FILE * avifile,unsigned int avi_fps,unsigned int avi_width,unsigned int avi_height);
int  avi_write(FILE * avifile, Avi_Data *avi_data, char * jpg_buff, unsigned int jpg_length);
void avi_create(FILE * avifile, Avi_Data *avi_data, unsigned int avi_fps, unsigned int avi_width, unsigned int avi_height, int avi_type,int ff);

void avi_close(FILE * avifile);

void * avi_read(FILE * avifile, unsigned int frame_number, unsigned int * jpg_size);

#ifdef __cplusplus
}
#endif

#endif